﻿using A.M.ETO;
using SqlSugar;
using System.Linq.Expressions;

namespace A.M.Storage.I_Infrastruecure
{
    public interface IBaseRepository<T,K> where T : class
    {
        #region 同步
        /// <summary>
        /// 单添加
        /// </summary>
        /// <param name="t">对象</param>
        /// <returns>受影响行数</returns>
        int AddInfor(T t);
        /// <summary>
        /// 批量添加
        /// </summary>
        /// <param name="t">集合</param>
        /// <returns>受影响行数</returns>
        int AddInfor_Batch(List<T> t);
        /// <summary>
        /// 单删除
        /// </summary>
        /// <param name="t">对象</param>
        /// <returns>受影响行数</returns>
        int DelInfor(T t);
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="t">集合</param>
        /// <returns>受影响行数</returns>
        int DelInfor_Batch(List<T> t);
        /// <summary>
        /// 单修改
        /// </summary>
        /// <param name="t">对象</param>
        /// <returns>受影响行数</returns>
        int UpdInfor(T t);
        /// <summary>
        /// 批量修改
        /// </summary>
        /// <param name="t">集合</param>
        /// <returns>受影响行数</returns>
        int UpdInfor_Batch(List<T> t);
        #endregion

        #region 异步
        /// <summary>
        /// 单添加_异步
        /// </summary>
        /// <param name="t">对象</param>
        /// <returns>受影响行数</returns>
        Task<int> AddInfor_Async(T t);
        /// <summary>
        /// 批量添加_异步
        /// </summary>
        /// <param name="t">集合</param>
        /// <returns>受影响行数</returns>
        Task<int> AddInfor_Batch_Async(List<T> t);
        /// <summary>
        /// 单删除_异步
        /// </summary>
        /// <param name="t">对象</param>
        /// <returns>受影响行数</returns>
        Task<int> DelInfor_Async(T t);
        /// <summary>
        /// 批量删除_异步
        /// </summary>
        /// <param name="t">集合</param>
        /// <returns>受影响行数</returns>
        Task<int> DelInfor_Batch_Async(List<T> t);
        /// <summary>
        /// 单修改_异步
        /// </summary>
        /// <param name="t">对象</param>
        /// <returns>受影响行数</returns>
        Task<int> UpdInfor_Async(T t);
        /// <summary>
        /// 批量修改_异步
        /// </summary>
        /// <param name="t">集合</param>
        /// <returns>受影响行数</returns>
        Task<int> UpdInfor_Batch_Async(List<T> t);
        #endregion

        #region 事务
        bool ExecuteTrans(Action<ISqlSugarClient> action);

        /// <summary>
        /// 开启事务
        /// </summary>
        void BeginTranInfor();

        /// <summary>
        /// 提交事务
        /// </summary>
        void CommitTranInfor();

        /// <summary>
        /// 回滚事务
        /// </summary>
        void RollbackTranInfor();
        #endregion

        #region 同步查询
        /// <summary>
        /// 无条件查询
        /// </summary>
        /// <returns>List<T></returns>
        List<T> GetShowInforOrder(Expression<Func<T, object>> orderInfor);

        /// <summary>
        /// 条件查询
        /// </summary>
        /// <param name="exception">条件</param>
        /// <returns>集合</returns>
        List<T> GetShowInforOrder(Expression<Func<T, bool>> exception, Expression<Func<T, object>> orderInfor);

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="pageSize">每页条数</param>
        /// <param name="pageIndex">当前页索引</param>
        /// <returns>分页查询 + 分页</returns>
        PageETO<T> GetShowInforOrder(int pageSize, int pageIndex, Expression<Func<T, object>> orderInfor);

        /// <summary>
        /// 条件查询 + 分页
        /// </summary>
        /// <param name="pageSize">每页条数</param>
        /// <param name="pageIndex">当前页索引</param>
        /// <param name="exception">查询条件</param>
        /// <returns>分页查询 + 分页</returns>
        PageETO<T> GetShowInforOrder(int pageSize, int pageIndex, Expression<Func<T, bool>> exception, Expression<Func<T, object>> orderInfor);

        /// <summary>
        /// 对象查询
        /// </summary>
        /// <param name="exception">表达式</param>
        /// <returns>对象</returns>
        T GetShowObj(Expression<Func<T, bool>> exception);

        /// <summary>
        /// 无条件查询（返回ISugarQueryable）
        /// </summary>
        /// <returns></returns>
        ISugarQueryable<T> GetShowQueryableOrder(Expression<Func<T, object>> orderInfor);

        /// <summary>
        /// 条件查询（返回ISugarQueryable）
        /// </summary>
        /// <param name="exception">查询条件</param>
        /// <returns>条件查询（返回ISugarQueryable）</returns>
        ISugarQueryable<T> GetShowQueryableOrder(Expression<Func<T,bool >> exception, Expression<Func<T, object>> orderInfor);

        /// <summary>
        /// 分页查询（返回ISugarQueryable）
        /// </summary>
        /// <param name="pageSize">每页条数</param>
        /// <param name="pageIndex">当前页</param>
        /// <returns>分页查询（返回ISugarQueryable）</returns>
        PageETO<T> GetShowQueryableOrder(int pageSize, int pageIndex, Expression<Func<T, object>> orderInfor);

        /// <summary>
        /// 查询 + 分页 （返回ISugarQueryable）
        /// </summary>
        /// <param name="pageSize">每页条数</param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="exception">查询条件</param>
        /// <returns>查询 + 分页 （返回ISugarQueryable）</returns>
        PageETO<T> GetShowQueryableOrder(int pageSize, int pageIndex, Expression<Func<T, bool>> exception, Expression<Func<T, object>> orderInfor);

        

        #endregion

        #region 异步查询
        /// <summary>
        /// 异步无条件查询
        /// </summary>
        /// <returns>List<T></returns>
        Task<List<T>> GetShowInforAsyncOrder(Expression<Func<T, object>> orderInfor);

        /// <summary>
        /// 异步条件查询
        /// </summary>
        /// <param name="exception">条件</param>
        /// <returns>集合</returns>
        Task<List<T>> GetShowInforAsyncOrder(Expression<Func<T, bool>> exception, Expression<Func<T, object>> orderInfor);

        /// <summary>
        /// 异步分页查询
        /// </summary>
        /// <param name="pageSize">每页条数</param>
        /// <param name="pageIndex">当前页索引</param>
        /// <returns>分页查询 + 分页</returns>
        Task<PageETO<T>> GetShowInforAsyncOrder(int pageSize, int pageIndex, Expression<Func<T, object>> orderInfor);

        /// <summary>
        /// 异步条件查询 + 分页
        /// </summary>
        /// <param name="pageSize">每页条数</param>
        /// <param name="pageIndex">当前页索引</param>
        /// <param name="exception">查询条件</param>
        /// <returns>分页查询 + 分页</returns>
        Task<PageETO<T>> GetShowInforAsyncOrder(int pageSize, int pageIndex, Expression<Func<T, bool>> exception, Expression<Func<T, object>> orderInfor);

        /// <summary>
        /// 异步对象查询
        /// </summary>
        /// <param name="exception">表达式</param>
        /// <returns>对象</returns>
        Task<T> GetShowObjAsync(Expression<Func<T, bool>> exception);

        /// <summary>
        /// 异步无条件查询（返回ISugarQueryable）
        /// </summary>
        /// <returns></returns>
        Task<ISugarQueryable<T>> GetShowQueryableAsyncOrder(Expression<Func<T, object>> orderInfor);

        /// <summary>
        /// 异步条件查询（返回ISugarQueryable）
        /// </summary>
        /// <param name="exception">查询条件</param>
        /// <returns>条件查询（返回ISugarQueryable）</returns>
        Task<ISugarQueryable<T>> GetShowQueryableAsyncOrder(Expression<Func<T, bool>> exception, Expression<Func<T, object>> orderInfor);

        /// <summary>
        /// 异步分页查询（返回ISugarQueryable）
        /// </summary>
        /// <param name="pageSize">每页条数</param>
        /// <param name="pageIndex">当前页</param>
        /// <returns>分页查询（返回ISugarQueryable）</returns>
        Task<PageETO<T>> GetShowQueryableAsyncOrder(int pageSize, int pageIndex, Expression<Func<T, object>> orderInfor);

        /// <summary>
        /// 异步查询 + 分页 （返回ISugarQueryable）
        /// </summary>
        /// <param name="pageSize">每页条数</param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="exception">查询条件</param>
        /// <returns>查询 + 分页 （返回ISugarQueryable）</returns>
        Task<PageETO<T>> GetShowQueryableAsyncOrder(int pageSize, int pageIndex, Expression<Func<T, bool>> exception, Expression<Func<T, object>> orderInfor);


        #endregion


        #region 同步查询
        /// <summary>
        /// 无条件查询
        /// </summary>
        /// <returns>List<T></returns>
        List<T> GetShowInfor();

        /// <summary>
        /// 条件查询
        /// </summary>
        /// <param name="exception">条件</param>
        /// <returns>集合</returns>
        List<T> GetShowInfor(Expression<Func<T, bool>> exception);

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="pageSize">每页条数</param>
        /// <param name="pageIndex">当前页索引</param>
        /// <returns>分页查询 + 分页</returns>
        PageETO<T> GetShowInfor(int pageSize, int pageIndex);

        /// <summary>
        /// 条件查询 + 分页
        /// </summary>
        /// <param name="pageSize">每页条数</param>
        /// <param name="pageIndex">当前页索引</param>
        /// <param name="exception">查询条件</param>
        /// <returns>分页查询 + 分页</returns>
        PageETO<T> GetShowInfor(int pageSize, int pageIndex, Expression<Func<T, bool>> exception);

        /// <summary>
        /// 无条件查询（返回ISugarQueryable）
        /// </summary>
        /// <returns></returns>
        ISugarQueryable<T> GetShowQueryable();

        /// <summary>
        /// 条件查询（返回ISugarQueryable）
        /// </summary>
        /// <param name="exception">查询条件</param>
        /// <returns>条件查询（返回ISugarQueryable）</returns>
        ISugarQueryable<T> GetShowQueryable(Expression<Func<T, bool>> exception);

        /// <summary>
        /// 分页查询（返回ISugarQueryable）
        /// </summary>
        /// <param name="pageSize">每页条数</param>
        /// <param name="pageIndex">当前页</param>
        /// <returns>分页查询（返回ISugarQueryable）</returns>
        PageETO<T> GetShowQueryable(int pageSize, int pageIndex);

        /// <summary>
        /// 查询 + 分页 （返回ISugarQueryable）
        /// </summary>
        /// <param name="pageSize">每页条数</param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="exception">查询条件</param>
        /// <returns>查询 + 分页 （返回ISugarQueryable）</returns>
        PageETO<T> GetShowQueryable(int pageSize, int pageIndex, Expression<Func<T, bool>> exception);

        /// <summary>
        /// 同步返回分页后数据
        /// </summary>
        /// <param name="pageSize">每页条数</param>
        /// <param name="pageIndex">当前页索引</param>
        /// <param name="values">传入的集合</param>
        /// <returns>同步返回分页后数据</returns>
        PageETO<T> GetPageShow(int pageSize, int pageIndex, List<T> values);

        #endregion

        #region 异步查询
        /// <summary>
        /// 异步无条件查询
        /// </summary>
        /// <returns>List<T></returns>
        Task<List<T>> GetShowInforAsync();

        /// <summary>
        /// 异步条件查询
        /// </summary>
        /// <param name="exception">条件</param>
        /// <returns>集合</returns>
        Task<List<T>> GetShowInforAsync(Expression<Func<T, bool>> exception);

        /// <summary>
        /// 异步分页查询
        /// </summary>
        /// <param name="pageSize">每页条数</param>
        /// <param name="pageIndex">当前页索引</param>
        /// <returns>分页查询 + 分页</returns>
        Task<PageETO<T>> GetShowInforAsync(int pageSize, int pageIndex);

        /// <summary>
        /// 异步条件查询 + 分页
        /// </summary>
        /// <param name="pageSize">每页条数</param>
        /// <param name="pageIndex">当前页索引</param>
        /// <param name="exception">查询条件</param>
        /// <returns>分页查询 + 分页</returns>
        Task<PageETO<T>> GetShowInforAsync(int pageSize, int pageIndex, Expression<Func<T, bool>> exception);

        /// <summary>
        /// 异步无条件查询（返回ISugarQueryable）
        /// </summary>
        /// <returns></returns>
        Task<ISugarQueryable<T>> GetShowQueryableAsync();

        /// <summary>
        /// 异步条件查询（返回ISugarQueryable）
        /// </summary>
        /// <param name="exception">查询条件</param>
        /// <returns>条件查询（返回ISugarQueryable）</returns>
        Task<ISugarQueryable<T>> GetShowQueryableAsync(Expression<Func<T, bool>> exception);

        /// <summary>
        /// 异步分页查询（返回ISugarQueryable）
        /// </summary>
        /// <param name="pageSize">每页条数</param>
        /// <param name="pageIndex">当前页</param>
        /// <returns>分页查询（返回ISugarQueryable）</returns>
        Task<PageETO<T>> GetShowQueryableAsync(int pageSize, int pageIndex);

        /// <summary>
        /// 异步查询 + 分页 （返回ISugarQueryable）
        /// </summary>
        /// <param name="pageSize">每页条数</param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="exception">查询条件</param>
        /// <returns>查询 + 分页 （返回ISugarQueryable）</returns>
        Task<PageETO<T>> GetShowQueryableAsync(int pageSize, int pageIndex, Expression<Func<T, bool>> exception);


        #endregion


    }
}
